const state = {
  age: null,
  annexBlackWhitePhoto: null,
  annexDegree: null,
  annexDiploma: null,
  annexDrivingLicense: null,
  annexEnglishLevel: null,
  annexHousehold: null,
  annexIdCard: null,
  annexMajor: null,
  annexNcreLevel: null,
  annexNoCriminal: null,
  annexNoPregnant: null,
  annexLeaving: null,
  annexPersonPhoto: null,
  annexPfCard: null,
  annexPractising: null,
  annexPthLevel: null,
  annexReward: null,
  annexSalaryCard: null,
  annexSocCard: null,
  approvalStatus: null,
  bankCard: null,
  bankCardBranch: null,
  bankName: null,
  bankPlace: null,
  bankPlaceId: null,
  birthStatus: null,
  birthday: null,
  birthplace: null,
  bloodGroup: null,
  changeStatus: null,
  companyId: null,
  companyName: null,
  contractsStatus: null,
  createUserId: null,
  currentAddrId: null,
  currentLocation: null,
  depIdList: null,
  depInfoList: null,
  depName: null,
  email: null,
  emerContact: null,
  emerLocation: null,
  emerPhone: null,
  empCardList: null,
  empCertificateList: null,
  empContactsList: [],
  empEducationList: [],
  empFamilyList: [],
  empPhoto: null,
  empTrainList: [],
  empWorkList: [],
  employType: true,
  englishLevel: null,
  formalType: 1,
  gender: null,
  hasWeightyMedicalHis: null,
  healthCondition: null,
  highestEducation: null,
  id: null,
  idCard: null,
  informalType: null,
  jobTitle: null,
  joinCityCode: null,
  joinCityName: null,
  joinDate: null,
  joinFormStatus: false,
  joinWorkDate: null,
  leaveDate: null,
  leaveReason: null,
  level: null,
  managerForm: null,
  maritalStatus: null,
  modifiedUserId: null,
  name: null,
  nation: null,
  nativeLocation: null,
  ncreLevel: null,
  number: null,
  partyDate: null,
  partySite: null,
  phone: null,
  politicalStatus: null,
  positionIdList: null,
  positionInfoList: null,
  positionName: null,
  postType: null,
  preJoinDate: null,
  preJoinDep: null,
  preJoinPosition: null,
  prizeWinning: null,
  probation: null,
  probationDays: null,
  putonghuaLevel: null,
  recruitChannels: null,
  regType: null,
  resStatus: null,
  retirementDate: null,
  retirementRemark: null,
  retirementStatus: false,
  siteId: null,
  socCard: null,
  socType: null,
  speciality: null,
  status: null,
  supervisor: null,
  targetPost: null,
  ticket: null,
  turnStraightDate: null,
  unionId: null,
  userId: null,
  userLoginVO: null,
  valid: true,
  verified: false,
  workCity: null,
  workCityId: null,
  workingUnitName: null
}

const mutations = {
  updateInfo: (state, payload) => {
    const payloadKeys = Object.keys(payload)
    const stateKeys = Object.keys(state)
    payloadKeys.map(key => {
      if (stateKeys.includes(key)) {
        state[key] = payload[key]
      }
    })
    uni.setStorageSync('employeeInfoTemp', JSON.stringify(state))
  },
  initInfo: (state, payload) => {
    const payloadKeys = Object.keys(payload)
    const employeeInfoTemp = uni.getStorageSync('employeeInfoTemp')
    const stateTemp = !!employeeInfoTemp ? JSON.parse(employeeInfoTemp) : null
    const stateKeys = Object.keys(state)
    payloadKeys.map(key => {
      if (stateKeys.includes(key)) {
        if (!!stateTemp) {
          if (['annexIdCard', 'idCard', 'birthday', 'name', 'gender', 'age', 'phone'].includes(key)) {
            state[key] = payload[key]
          } else {
            state[key] = stateTemp[key]
          }
        } else {
          state[key] = payload[key]
        }
      }
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations
}
